import numpy as np
from matplotlib import pyplot as plt

#====================================DATA
def polynom(min,max,theta,nahoda):
	'''
	Vytvari data nahodne rozmistena kolem polynomu libovolneho stupne v zavislosti na poctu prvku v parametru theta.
	pouziti y=0*x^0+2*x^1:
	[x,y]=generovaniDat.generujDataPolynom(1,100,[0,2],2)
	'''

	x=np.arange(min,max,1.0)

	X=np.zeros((len(theta),len(x)))
	for i in range(0,len(theta)):
		X[i]=pow(x,i)
	
	#vektorovy soucin
	y=np.dot(theta,X)

	#chyba normalni rozdeleni
	x+=nahoda*(np.random.randn(len(x)))
	y+=nahoda*(np.random.randn(len(x)))

	return x,y

def multiVariable(minMax,pocet,theta,nahoda):
	'''
	Vytvari data nahodne rozmistena kolem funkce n promennych.
	pouziti y=0*x_0+2*x_1
	'''
	X=np.zeros((minMax.shape[0],pocet))
	for i in range(0,minMax.shape[0]):
		X[i]=np.linspace(minMax[i,0],minMax[i,1],pocet)
	y=np.dot(theta, X)
	y+=nahoda*(np.random.randn(len(y)))
	
	return X,y

def generujDataKlasifikace(min,max,classes,nahoda):
#classes example [[[0],[2],[0]],[[4],[6],[1]]]
	x=np.arange(min,max,0.1)
	y=np.zeros(len(x))
	for it in range(0,len(x)):
		for c in classes:
			if (x[it]>=c[0] and x[it]<=c[1]):
				y[it]=c[2]
	data=plt.subplot(1,1,1)
	x+=nahoda*(np.random.randn(len(x)))
	y+=0.01*(np.random.randn(len(x)))
	
	data.plot(x,y, "b.")
	plt.xlabel('X')
	plt.ylabel('Labels')
	data.set_title("Data: classification")
	plt.show()

def generujDataShlukovani(min,max,classes,nahoda):
#classes example [[[0],[2],[r]],[[4],[6],[b]]]
	x=np.arange(min,max,0.1)
	y=np.zeros(len(x))
	color=range(0,len(x))
	for it in range(0,len(x)):
		for c in classes:
			if (x[it]>=c[0] and x[it]<=c[1]):
				color[it]=c[2]
	data=plt.subplot(1,1,1)
	x+=nahoda*(np.random.randn(len(x)))
	y+=0.01*(np.random.randn(len(x)))
	
	for it in range(0,len(x)):
		data.plot(x[it],y[it], str(color[it])+".")
		

	plt.xlabel('X')
	plt.ylabel('Labels')
	#plt.ylim(-1,1)
	data.set_title("Data: clustering")
	plt.show()

def generujDataOdhadHustoty(min,max,classes,nahoda):
#classes example [[[0],[2],[r]],[[4],[6],[b]]]
	x=np.arange(min,max,0.1)
	y=np.zeros(len(x))
	color=range(0,len(x))
	for it in range(0,len(x)):
		for c in classes:
			if (x[it]>=c[0] and x[it]<=c[1]):
				color[it]=c[2]
	data=plt.subplot(1,1,1)
	x+=nahoda*(np.random.randn(len(x)))
	y+=0.01*(np.random.randn(len(x)))
	
	for it in range(0,len(x)):
		data.plot(x[it],y[it], str(color[it])+".")
		

	plt.xlabel('X')
	plt.ylabel('Labels')
	plt.ylim(-1,1)
	data.set_title("Data: probability density estimation")
	plt.show()
